package com.xiaoshuidi.cloud.module.contract.api.contract;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.api.ContractRoomAccountApi;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.roommeta.ContractRoommateDO;
import com.xiaoshuidi.cloud.module.contract.service.roommate.ContractRoommateService;
import com.xiaoshuidi.cloud.module.contract.vo.CustomerVO;
import com.xiaoshuidi.cloud.module.finance.enums.finance.FinanceCustomerTypeEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@Validated
@RequiredArgsConstructor
public class ContractRoomAccountApiImpl implements ContractRoomAccountApi {
    @Resource
    private ContractRoommateService contractRoommateService;

    @Override
    public CommonResult<List<CustomerVO>> getAllCompanyCheckinRoom(Long memberId) {
        List<ContractRoommateDO> l = contractRoommateService.getAllCompanyCheckinRoom(memberId);
        return CommonResult.success(l.stream().map(r -> CustomerVO.builder()
                .id(r.getMemberId())
                .type(FinanceCustomerTypeEnum.ROOM.name())
                .roomId(r.getRoomId())
                .companyId(r.getCustomerCompanyId())
                .roomName(r.getRoomName())
                .tenantId(r.getTenantId())
                .companyName(r.getCustomerCompanyName())
                .apartmentId(r.getApartmentId())
                .apartmentName(r.getApartmentName())
                .startTime(r.getStartTime())
                .build()).collect(Collectors.toList()));
    }
}
